package com.aiks.dsyncpluginspringbootautoconfigure;

import com.aiks.dsyncpluginspringbootautoconfigure.plugin.Plugin;
import com.aiks.dsyncpluginspringbootautoconfigure.plugin.factory.PluginFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.support.SpringFactoriesLoader;

/**
 * DsyncPluginConfiguration.
 *
 * @author <a href="mailto:aiks_yuan@163.com">yuanz</a>
 * @date 2022-07-19 10:50 上午
 * @since 1.0.0
 **/
@Configuration
@ConditionalOnClass(Plugin.class)
@Import(SpringContext.class)
@AutoConfigureAfter(SpringContext.class)
public class DsyncPluginFactoryConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "dsync", name = "plugin.factory", matchIfMissing = true)
    public PluginFactory getPluginFactory() {
        PluginFactory instance = PluginFactory.INSTANCE;
        instance.init(SpringFactoriesLoader.loadFactories(Plugin.class, this.getClass().getClassLoader()));
        return instance;
    }

}
